<template>
  <div class="container" ref="container">
    <!-- 顶部 -->
    <div class="task_header">
      <div class="top_title">
        <div class="top_title_back" @click="onClickLeft">
          <i class="iconfont icon-back"></i>
        </div>
        <div class="top_title_val">{{ $route.meta.title }}</div>
      </div>
    </div>
    <div class="info">
      <div class="info_item">
        <div class="info_label">会员手机号</div>
        <div class="info_val">
          <input v-model="requestParams.phone" type="number" class="info_input" placeholder="请输入完整手机号码" @input="onInput" />
          <span v-if="requestParams.phone" class="iconfont icon-del" @click="requestParams.phone = ''"></span>
        </div>
      </div>
      <div class="info_item">
        <div class="info_label">车牌或车架号</div>
        <div class="info_val">
          <input v-model="requestParams.carNo" class="info_input" placeholder="请输入完整车牌或车架号" @blur="onBlur" />
          <span v-if="requestParams.carNo" class="iconfont icon-del" @click="requestParams.carNo = ''"></span>
        </div>
      </div>
      <div class="searchBtn" @click="handleSubmit">查询</div>
      <div class="tips">请输入手机号或者车牌或车架号其一进行查询</div>

<!--      <div style="margin-top: 100px;text-align: center;"><router-link to="/bindCarIndex" style="color: #409EFF;text-decoration: underline;font-size: 17px">绑车记录查询➡️</router-link></div>-->

    </div>
    <van-dialog v-model="showDialog" title="提示" show-cancel-button :showConfirmButton="false">
      <div class="member_dialog">
        <div class="member_title">当前车牌存在多条会员信息请选择查看</div>
        <div class="memberList">
          <div class="member_item" v-for="(item, index) in memberList" :key="index" @click="goDetail(item)">
            <div class="item_info">
              <div class="item_box">
                <div class="item_label">手机：</div>
                <div class="item_val">{{ item.mobile }}</div>
              </div>
              <div class="item_box mb0">
                <div class="item_label">昵称：</div>
                <div class="item_val">{{ item.memberName }}</div>
              </div>
            </div>

            <span class="iconfont icon-right"></span>
          </div>
        </div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import { Dialog, Toast } from 'vant'
import vipInfoApi from '@/api/vipInfoApi'

export default {
  name: 'vipInfo',
  components: { Toast, Dialog },
  data() {
    return {
      requestParams: {
        phone: '',
        carNo: '',
        // carNo: '湘L666UP',
      },
      showDialog: false,
      memberList: [],
    }
  },
  watch: {
    requestParams: {
      handler: function (val, oldVal) {},
      deep: true,
      immediate: false,
    },
  },

  mounted() {},

  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    toUpperCase(str) {
      return str.replace(/[a-z]/g, function (match) {
        return match.toUpperCase()
      })
    },
    onBlur() {
      this.requestParams.carNo = this.toUpperCase(this.requestParams.carNo)
    },
    onInput() {
      if (this.requestParams.phone.length > 11) {
        this.requestParams.phone = this.requestParams.phone.slice(0, 11)
      }
    },
    handleSubmit() {
      if (!this.requestParams.phone && !this.requestParams.carNo) {
        Toast('请输入手机号或者车牌号码进行查询')
        return
      }
      if (this.requestParams.phone && this.requestParams.phone.length < 11) {
        Toast('当前手机号码格式不正确')
        return
      }
      Toast.loading('查询中...')
      vipInfoApi.getMemberInformationByList(this.requestParams).then((res) => {
        Toast.clear()
        if (res.code == 1) {
          if (res.data && res.data.length > 0) {
            if (res.data.length > 1) {
              this.showDialog = true
              this.memberList = res.data
            } else {
              this.$router.push({ path: '/vipInfodetail', query: { memberId: res.data[0].memberId } })
            }
          } else {
            Toast('暂未查到数据')
          }
        }
      })
    },
    goDetail(data) {
      this.$router.push({ path: '/vipInfodetail', query: { memberId: data.memberId } })
    },
  },
}
</script>

<style lang="less" scoped="">
.task_header {
  background: url('~@/assets/images/title_bg.png') no-repeat center;
  font-size: 0.24rem;
  height: 45px;
  background-size: 100% 100%;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 9;

  .top_title {
    position: relative;
    width: 100%;
    height: 50px;

    .top_title_back {
      position: absolute;
      left: 10px;
      line-height: 50px;
      color: #fff;
    }

    .top_title_val {
      text-align: center;
      line-height: 50px;
      color: #fff;
      font-weight: bold;
      font-size: 16px;
    }
    .task_transbox {
      position: absolute;
      right: 10px;
      top: 20px;
      color: #fff;
      z-index: 10;
      font-weight: 400;
      font-size: 12px;
      text-align: center;
      .task_trans {
        width: 24px;
        display: block;
        margin: auto;
      }
    }
  }

  .task_header_data {
    .task_header_date {
      margin-bottom: 10px;
      display: flex;
      align-items: center;

      .task_header_date_w {
        width: 12.5%;
      }

      .task_header_date_item {
        width: 12.5%;
        text-align: center;
        color: #fff;
        font-size: 14px;
      }
    }

    .task_header_followData {
      display: flex;
      align-items: center;
      color: #fff;
      margin-bottom: 10px;

      .task_header_followData_tt {
        width: 12.5%;
        text-align: center;
      }

      .task_header_followData_item {
        width: 12.5%;
        text-align: center;
        font-size: 12px;
        font-weight: bold;
      }
    }
  }
}
.info {
  padding-top: 90px;
  width: 300px;
  margin: auto;
  .info_item {
    font-size: 14px;
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    .info_label {
      margin-right: 10px;
      width: 120px;
    }
    .info_val {
      width: 190px;
      border: 1px solid #3975c6;
      border-radius: 40px;
      height: 38px;
      display: flex;
      align-items: center;
      padding-right: 10px;
      flex-shrink: 0;
      .info_input {
        padding-left: 10px;
        background: none;
      }
      .icon-del {
        font-size: 16px;
      }
    }
  }
  .searchBtn {
    width: 300px;
    margin: auto;
    text-align: center;
    font-size: 14px;
    background: linear-gradient(316deg, #3975c6 0%, #71a4ea 100%);
    color: #fff;
    padding: 12px 0rem;
    border-radius: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 50px;
  }
  .tips {
    text-align: left;
    font-size: 16px;
    color: #999;
    margin-top: 40px;
  }
}
::-webkit-input-placeholder {
  color: #a3a3a3;
}
.member_dialog {
  .member_title {
    text-align: center;
    font-size: 14px;
    color: #999;
    margin-top: 10px;
  }
  .memberList {
    max-height: 350px;
    overflow: auto;
    padding: 10px 20px;
    .member_item {
      background: #f8f8f8;
      padding: 15px 20px;
      border-radius: 5px;
      margin-bottom: 10px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .item_info {
        .item_box {
          display: flex;
          align-items: center;
          margin-bottom: 10px;

          .item_label {
            font-size: 14px;
          }
          .item_val {
            font-size: 14px;
          }
        }
      }
      .icon-right {
        font-size: 20px;
      }
    }
  }
}
.mb0 {
  margin-bottom: 0 !important;
}
</style>
